package com.xwltz.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Aspect
@Component
public class LoggerAspect {

    @Before(value = "execution(public int com.xwltz.utils.impl.CalImpl.*(..))")
    public void before(JoinPoint joinPoint) {
        String method = joinPoint.getSignature().getName();
        String args = Arrays.toString(joinPoint.getArgs());
        System.out.println(method + "方法的参数是" + args);
    }

    @After(value = "execution(public int com.xwltz.utils.impl.CalImpl.*(..))")
    public void after(JoinPoint joinPoint) {
        String method = joinPoint.getSignature().getName();
        System.out.println(method + "执行中..");
    }

    @AfterReturning(value = "execution(public int com.xwltz.utils.impl.CalImpl.*(..))", returning = "result")
    public void afterReturning(JoinPoint joinPoint, Object result) {
        String method = joinPoint.getSignature().getName();
        System.out.println(method + "方法的结果是" + result);
    }

    @AfterThrowing(value = "execution(public int com.xwltz.utils.impl.CalImpl.*(..))", throwing = "exception")
    public void afterThrowing(JoinPoint joinPoint, Exception exception) {
        String method = joinPoint.getSignature().getName();
        System.out.println(method + "方法抛出异常：" + exception);
    }
}
